package com.nbicc.dp.web.panelwidgetinstance.controller;

import com.nbicc.core.common.RequestPageObj;
import com.nbicc.db.modular.dp.panelwidgetinstance.model.PanelWidgetInstance;
import com.nbicc.service.modular.dp.panelwidgetinstance.service.PanelWidgetInstanceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author: lilingyan
 */
@Api(value = "dp:面板与控件关系" , description = "定义控件在哪个面板上的什么位置")
@RestController
@RequestMapping("/panel/widget/instance")
public class PanelWidgetInstanceController {

    @Autowired
    private PanelWidgetInstanceService panelWidgetInstanceService;

    @ApiOperation(value = "按面板查询所有控件")
    @GetMapping("/{panelId:.+}")
    public ResponseEntity<ModelMap> listByPanelId(@PathVariable Integer panelId){
        return panelWidgetInstanceService.listByPanelId(panelId);
    }

    @ApiOperation(value = "分页查询")
    @PostMapping("/find")
    public ResponseEntity<ModelMap> find(@RequestBody RequestPageObj<Map<String,Object>> requestPageObj){
        return panelWidgetInstanceService.find(requestPageObj);
    }

    @ApiOperation(value = "添加" , notes = "id自动生成并返回")
    @PostMapping
    public ResponseEntity<ModelMap> insert(@RequestBody PanelWidgetInstance panelWidgetInstance){
        return panelWidgetInstanceService.insert(panelWidgetInstance);
    }

    @ApiOperation(value = "修改", notes = "以id修改")
    @PutMapping
    public ResponseEntity<ModelMap> updateById(@RequestBody PanelWidgetInstance panelWidgetInstance){
        return panelWidgetInstanceService.updateById(panelWidgetInstance);
    }

    @ApiOperation(value = "删除", notes = "以序列号")
    @DeleteMapping("/{id:.+}")
    public ResponseEntity<ModelMap> deleteById(@PathVariable String id){
        return panelWidgetInstanceService.deleteById(id);
    }

}
